package listbyorder.access101_200.test120;

import java.util.List;

/**
 * @author code_yc
 * @version 1.0
 * @date 2020/6/8 12:55
 */
public class Solution2 {

    // 方法二： 动态规划
    public int minimumTotal(List<List<Integer>> triangle) {
        if (triangle == null) return 0;
        int size = triangle.size();
        int[][] dp = new int[size][size];
        for (int i = size - 1; i >= 0; i--) {
            for (int j = i; j >= 0; j--) {
                if (i == size - 1) {
                    dp[i][j] = triangle.get(i).get(j);
                } else {
                    dp[i][j] = Math.min(dp[i + 1][j], dp[i + 1][j + 1]) + triangle.get(i).get(j);
                }
            }
        }
        return dp[0][0];
    }

}
